package org.zfes.snowier.cloud.zbss.widget.act.route.service.tea;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zfes.snowier.core.util.ZAssert;
import org.zfes.snowier.core.util.ZStrUtil;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.auth.shiro.util.SecurityUtil;
import org.zfes.snowier.cloud.zbss.widget.act.dto.SubQuestionsDto;
import org.zfes.snowier.cloud.zbss.widget.act.service.IActSubjectQuestionsService;
@Controller("org.zfes.snowier.cloud.zbss.widget.act.route.service.tea.actSubjectQuestionsController") 
@RequestMapping("/active/service/tea/actSubjectQuesList")
public class ActSubjectQuestionsController extends BaseController {

	
	@Autowired
	private IActSubjectQuestionsService actSubjectQuestionsService;
	
	//新增课堂题目
    @RequestMapping(value="/createActSubjectQuestions", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object createActSubjectQuestions(Long subjectId, List<Long> quesIds){
		actSubjectQuestionsService.createActSubjectQuestions(subjectId, quesIds, SecurityUtil.getUserId().get());
    	return ajaxDoneSuccess("数据操作成功 ");
    }
    //删除课堂题目
    @RequestMapping(value="/deleteActSubjectQuesList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object deleteActSubjectQuesList(Long id){
		actSubjectQuestionsService.deleteActSubjectQuestions(id,  SecurityUtil.getUserId().get());
		return ajaxDoneSuccess("数据操作成功 ");
    }
    
    //修改题目顺序
    @RequestMapping(value="/updateActSubjectQuesOrder", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateActSubjectQuesOrder(Long id,Integer newOrder){
		actSubjectQuestionsService.updateActSubjectQuesOrder(id, newOrder);
		return ajaxDoneSuccess("数据操作成功 ");
    }
    
    
    //出题
    @RequestMapping(value="/assignQuestionProcess", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object assignQuestionProcess(String ids,Long subjectId) {
    	ZAssert.hasText(ids, "请选择题目");
    	SubQuestionsDto subQuestionsDto=actSubjectQuestionsService
    				.assignQuestionProcess(ZStrUtil.splitLong(ids), subjectId,  SecurityUtil.getUserId().get());
    	return ajaxQuery("subQuestionsDto", subQuestionsDto);
    	  
	 }
    
    // 加载课堂题目数据
    @RequestMapping(value="/loadActSubjectQuestionsDto", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadActSubjectQuestionsDto(Long subjectId,Boolean onlyUnAssigned) {
    	
    	SubQuestionsDto subQuestionsDto=actSubjectQuestionsService
    				.loadActSubjectQuestionsDto( subjectId,  SecurityUtil.getUserId().get(),onlyUnAssigned);
    	return ajaxQuery("subQuestionsDto", subQuestionsDto);
	 }
  
}